"use strict";
/* Controllers */
app.controller("alertLogDetailController", ['$scope', '$location', '$rootScope', '$routeParams', 'alertLogDetailService', function ($scope, $location, $rootScope, $routeParams, alertLogDetailService) {

    var vm = $scope.vm = {};
    vm.p = {};
    vm.p.id = $routeParams.id; // 如果ID!=0为更新

    var errorFn = function (result) {
        alert(result);
    };


    $scope.setAlertLog = function () {
        var vm = $scope.vm;
        var params = {
            id: vm.p.id,
            alertTitle: vm.p.alertTitle,
            alertContent: vm.p.alertContent,
            isAlert: vm.p.isAlert,
            ruleName: vm.p.ruleName,
            ruleCode: vm.p.ruleCode
        };
        var procFn = function (response) {
            if (response.success && response.data) {
                //window.location = "#/star/alertLog/alertLog_list";
                alert("执行成功！")
            } else {
                alert(response.msg);
            }
        };
        alertLogDetailService.setAlertLog(params, procFn, errorFn);
    };
    $scope.getAlertLog = function () {
        var vm = $scope.vm;
        var params = {
            id: vm.p.id
        };
        var procFn = function (response) {
            if (response.success && response.data) {
                //vm.p = JSON.stringify(response.data);
                vm.p = response.data;
            } else {
                alert(response.msg);
            }
        };
        alertLogDetailService.getAlertLog(params, procFn, errorFn);
    };

    //
    if(vm.p.id!=0) {
        $scope.getAlertLog();
    }
}]);


/* Services */
app.service('alertLogDetailService', ['ajaxService', function (ajaxService) {

    this.setAlertLog = function (params, successFunction, errorFunction) {
        ajaxService.AjaxPost(params, "/star/api/basic-service/v1/alert_log/setAlertLog.do", successFunction, errorFunction);
    };
    this.getAlertLog = function (params, successFunction, errorFunction) {
        ajaxService.AjaxPost(params, "/star/api/basic-service/v1/alert_log/getAlertLog.do", successFunction, errorFunction);
    };
}]);

